<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <input type="hidden" name="dateNow" id="dateNow"
                           th:value="${#dates.format(new java.util.Date().getTime(), 'yyyy-MM-dd')}"/>
                    <input type="hidden" name="roleKey" id="roleKey" th:value="${roleKey}"/>
                    <ul>
                        <li>
                            订单id：<input type="text" name="id"/>
                        </li>
                        <li>
                            订单编号：<input type="text" name="orderNo"/>
                        </li>
                        <li>
                            商户名称：<input type="text" name="merchantName"/>
                        </li>
                        <li>
                            订单状态：
                            <select name="orderStatus" th:with="type=${@dict.getType('sys_new_order_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            清分状态：
                            <select name="clearingStatus" th:with="type=${@dict.getType('sys_new_order_clearing')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            通道名称：<input type="text" name="acqName"/>
                        </li>
                        <li>
                            银行卡号：<input type="text" name="creditNumber"/>
                        </li>
                        <li class="select-time">
                            <label>交易金额： </label>
                            <input type="text" name="params[sAmountMoney]"/>
                            <span>-</span>
                            <input type="text" name="params[eAmountMoney]"/>
                        </li>
                        <li>
                            订单类型：
                            <input name="params[orderTypes]" id="orderTypes" type="hidden">
                            <label th:each="role:${@dict.getType('sys_new_order_type')}" class="check-box">

                                <input name="orderType1" id="orderType1" type="checkbox" th:value="${role.dictValue}"
                                       th:text="${role.dictLabel}">
                            </label>
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text"
                                   class="time-input" id="completeTimeStartTime1" placeholder="开始时间"
                                   name="params[completeTimeStartTime1]"/>
                            <span>-</span>
                            <input type="text"
                                   class="time-input" id="completeTimeEndTime1" placeholder="结束时间"
                                   name="params[completeTimeEndTime1]"/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" th:onclick="search1()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="reset('formId')"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                        <li>
                            <label class="text-warning" style="font-size:20px">交易笔数：<label id="number">0</label></label>
                            <label class="text-warning" style="font-size:18px">交易金额：<label
                                    id="totalMoney">0</label></label>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
            <a class="btn btn-success" onclick="saveSettleList()">
                手工清分T+0
            </a>
            <a class="btn btn-success" onclick="$.operate.add()"  shiro:hasPermission="system:paymentOrder:export" >
                <i class="fa fa-plus"></i> 导入合伙人订单
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()"
               shiro:hasPermission="system:paymentOrder:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:paymentOrder:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:paymentOrder:remove')}]];
    var prefix = ctx + "system/paymentOrder";
    var orderStatus = [[${@dict.getType('sys_new_order_status')}]];
    var orderClearing = [[${@dict.getType('sys_new_order_clearing')}]];
    var acqType = [[${@dict.getType('sys_acq_type')}]];
    var orderType = [[${@dict.getType('sys_new_order_type')}]];

    function search1() {
        if ($("#completeTimeStartTime1").val() == "" || $("#completeTimeEndTime1").val() == "") {
            $.modal.alertWarning("请选择创建时间")
        } else {
            var beginTime = $("#completeTimeStartTime1").val();
            var endTime = $("#completeTimeEndTime1").val();
            var d1 = new Date(beginTime);
            var d2 = new Date(endTime);
            if ((parseInt(d2 - d1) / (3600000 * 24)) > 31) {
                $.modal.alertWarning("时间间隔不能大于一个月")
            } else {
                var test = $("input[name='orderType1']:checked");
                var checkBoxValue = "";
                test.each(function () {
                    checkBoxValue += $(this).val() + ",";
                })
                checkBoxValue = checkBoxValue.substring(0, checkBoxValue.length - 1);
                $("#orderTypes").val(checkBoxValue)
                $("#number").text(0);
                $("#totalMoney").text(0);
                $.table.search("formId");
            }
        }
    }

    //清分
    function saveSettleList() {
        $.modal.confirm("确认要手动清分吗？", function () {
            $.operate.post(prefix + "/manualClearing", {});
        })
    }

    $(function () {
        $("#completeTimeStartTime1").val($("#dateNow").val() + " 00:00:00")
        $("#completeTimeEndTime1").val($("#dateNow").val() + " 23:59:59")
    })

    //重置form
    function reset(formId) {
        var test = $("input[name='orderType1']:checked");
        test.each(function () {
            $(this).parent().removeClass("icheckbox-blue checked");
            $(this).parent().addClass("icheckbox-blue");

        })
        var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
        $("#" + currentId)[0].reset();

        $("#number").text(0);
        $("#totalMoney").text(0);
        $("#completeTimeStartTime1").val($("#dateNow").val() + " 00:00:00")
        $("#completeTimeEndTime1").val($("#dateNow").val() + " 23:59:59")
    }


    $(function () {
        if ($("#roleKey").val() == "admin") {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "交易订单列表",
                queryParams: queryParams,
                sortName: "createTime",
                sortOrder: "desc",
                search: false,
                showExport: true,
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'id',
                        title: '',
                        visible: true,
                        formatter: function (value, row, index) {
                            if (row.number != null && row.totalMoney != null) {
                                $("#number").text(parseFormatNum(row.number, 0));
                                $("#totalMoney").text(parseFormatNum(row.totalMoney, 2))
                            }
                            return "";
                        }
                    },
                    {
                        field: 'id',
                        title: '订单id',
                        align: 'center',
                    },
                    {
                        field: 'orderNo',
                        align: 'center',
                        title: '订单编号',
                        formatter: function (value, row, index) {
                            return '<a href="#" onclick="detail(\'' + row.id + '\')">' + value + '</a>';
                        }
                    },
                    {
                        field: 'merchantName',
                        title: '商户名称',
                        align: 'center',
                    },

                    {
                        field: 'orderStatus',
                        align: 'center',
                        title: '订单状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(orderStatus, value);
                        }
                    },
                    {
                        field: 'orderType',
                        align: 'center',
                        title: '订单类型',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(orderType, value);
                        }
                    },
                    {
                        field: 'acqReturnMsg',
                        align: 'center',
                        title: '通道返回信息',
                        formatter: function (value, row, index) {
                            return "<strong style='color: red's>" + value + "</strong>";
                        }
                    },
                    {
                        field: 'acqName',
                        title: '通道名称',
                        align: 'center',
                        formatter: function (value, row, index) {
                            if (value != null && value != "") {
                                return "<strong style='color: #1E0FBE's>" + value + "</strong>";
                            }
                            return ""
                        }
                    },
                    {
                        field: 'creditNumber',
                        title: '卡号',
                        align: 'center',
                    },
                    {
                        field: 'bankName',
                        align: 'center',
                        title: '所属银行',
                        formatter: function (value, row, index) {
                            if (value != null && value != "") {
                                return "<strong style='color: #1E0FBE's>" + value + "</strong>";
                            }
                            return ""
                        }
                    },
                    {
                        field: 'amountMoney',
                        align: 'center',
                        title: '交易金额',
                        formatter: function (value, row, index) {
                            return "<strong style='color: red's>" + value + "</strong>";
                        }
                    },
                    {
                        field: 'profitMoney',
                        title: '收益',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return "<strong style='color: red's>" + value + "</strong>";
                        }
                    },
                    {
                        field: 'clearingStatus',
                        align: 'center',
                        title: '清分状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(orderClearing, value);
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var actions = [];
                            if (row.orderType != 6) {//查询订单
                                actions.push('<a class="btn btn-success btn-xs ' + '" href="#" onclick="findOrderGG(\'' + row.id + '\')">查询订单</a> ');
                            }
                            if (row.orderType == 1 && row.orderStatus == 1) {//养卡消费退款
                                actions.push('<a class="btn btn-danger btn-xs ' + '" href="#" onclick="daiFuRepairOrderGG(\'' + row.id + '\')">养卡消费退款</a> ');
                            } else if (row.orderType == 3 && row.orderStatus == 2) {//无卡出款
                                actions.push('<a class="btn btn-danger btn-xs ' + '" href="#" onclick="daiFuRepairOrderGGWK(\'' + row.id + '\')">无卡出款</a>')
                            }
                            return actions.join('');
                        }
                    },
                    {
                        field: 'createTime',
                        title: '订单创建时间',
                        align: 'center',
                    },
                    {
                        field: 'completeTime',
                        title: '订单完成时间',
                        align: 'center',
                    },
                    {
                        field: 'costRateMoney',
                        title: '成本手续费',
                        align: 'center',
                    },
                    {
                        field: 'rateMoney',
                        title: '实扣手续费',
                        align: 'center',
                    }
                ]
            };
            $.table.init(options);
        } else if ($("#roleKey").val() == "cs") {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "交易订单列表",
                queryParams: queryParams,
                sortName: "createTime",
                sortOrder: "desc",
                search: false,
                showExport: true,
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'id',
                        title: '',
                        visible: true,
                        formatter: function (value, row, index) {
                            if (row.number != null && row.totalMoney != null) {
                                $("#number").text(parseFormatNum(row.number, 0));
                                $("#totalMoney").text(parseFormatNum(row.totalMoney, 2))
                            }
                            return "";
                        }
                    },
                    {
                        field: 'orderNo',
                        align: 'center',
                        title: '订单编号',
                        formatter: function (value, row, index) {
                            return '<a href="#" onclick="detail(\'' + row.id + '\')">' + value + '</a>';
                        }
                    },
                    {
                        field: 'merchantName',
                        title: '商户名称',
                        align: 'center',
                    },
                    {
                        field: 'orderStatus',
                        align: 'center',
                        title: '订单状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(orderStatus, value);
                        }
                    },
                    {
                        field: 'orderType',
                        align: 'center',
                        title: '订单类型',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(orderType, value);
                        }
                    },
                    {
                        field: 'acqReturnMsg',
                        align: 'center',
                        title: '通道返回信息',
                        formatter: function (value, row, index) {
                            return "<strong style='color: red's>" + value + "</strong>";
                        }
                    },
                    {
                        field: 'acqName',
                        title: '通道名称',
                        align: 'center',
                        formatter: function (value, row, index) {
                            if (value != null && value != "") {
                                return "<strong style='color: #1E0FBE's>" + value + "</strong>";
                            }
                            return ""
                        }
                    },
                    {
                        field: 'creditNumber',
                        title: '卡号',
                        align: 'center',
                    },
                    {
                        field: 'bankName',
                        align: 'center',
                        title: '所属银行',
                        formatter: function (value, row, index) {
                            if (value != null && value != "") {
                                return "<strong style='color: #1E0FBE's>" + value + "</strong>";
                            }
                            return ""
                        }
                    },
                    {
                        field: 'amountMoney',
                        align: 'center',
                        title: '交易金额',
                        formatter: function (value, row, index) {
                            return "<strong style='color: red's>" + value + "</strong>";
                        }
                    },
                    {
                        field: 'profitMoney',
                        title: '收益',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return "<strong style='color: red's>" + value + "</strong>";
                        }
                    },
                    {
                        field: 'clearingStatus',
                        align: 'center',
                        title: '清分状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(orderClearing, value);
                        }
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var actions = [];
                            //订单类型（0 无卡消费 1养卡消费 2养卡代付3无卡出款4退款5提现 6充值升级）
                            //订单状态（0处理中1成功2失败3已补单    9回    ）
                            if (row.orderType != 6) {//查询订单
                                actions.push('<a class="btn btn-success btn-xs ' + '" href="#" onclick="findOrderGG(\'' + row.id + '\')">查询订单</a> ');
                            }
                            if (row.orderType == 1 && row.orderStatus == 1) {//养卡消费退款
                                actions.push('<a class="btn btn-danger btn-xs ' + '" href="#" onclick="daiFuRepairOrderGG(\'' + row.id + '\')">养卡消费退款</a> ');
                            } else if (row.orderType == 3 && row.orderStatus == 2) {//无卡出款
                                actions.push('<a class="btn btn-danger btn-xs ' + '" href="#" onclick="daiFuRepairOrderGGWK(\'' + row.id + '\')">无卡出款</a>')
                            }
                            return actions.join('');
                        }
                    },
                    {
                        field: 'createTime',
                        title: '订单创建时间',
                        align: 'center',
                    },
                    {
                        field: 'completeTime',
                        title: '订单完成时间',
                        align: 'center',
                    },
                    /* {
                         field: 'costRateMoney',
                         title: '成本手续费',
                         align: 'center',
                     },
                     {
                         field: 'rateMoney',
                         title: '实扣手续费',
                         align: 'center',
                     }*/
                ]
            };
            $.table.init(options);
        } else {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "交易订单列表",
                queryParams: queryParams,
                search: false,
                showExport: true,
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'id',
                        title: '',
                        visible: true,
                        formatter: function (value, row, index) {
                            if (row.number != null && row.totalMoney != null) {
                                $("#number").text(parseFormatNum(row.number, 0));
                                $("#totalMoney").text(parseFormatNum(row.totalMoney, 2))
                            }
                            return "";
                        }
                    },
                    {
                        field: 'orderNo',
                        align: 'center',
                        title: '订单编号',
                        formatter: function (value, row, index) {
                            return '<a href="#" onclick="detail(\'' + row.id + '\')">' + value + '</a>';
                        }
                    },
                    {
                        field: 'merchantName',
                        title: '商户名称',
                        align: 'center',
                    },
                    {
                        field: 'agentName',
                        title: '代理商姓名',
                        align: 'center',
                    },
                    {
                        field: 'agentPhone',
                        title: '代理手机号',
                        align: 'center',
                    },
                    {
                        field: 'orderStatus',
                        align: 'center',
                        title: '订单状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(orderStatus, value);
                        }
                    },
                    {
                        field: 'orderType',
                        align: 'center',
                        title: '订单类型',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(orderType, value);
                        }
                    },
                    {
                        field: 'acqName',
                        title: '通道名称',
                        align: 'center',
                        formatter: function (value, row, index) {
                            if (value != null && value != "") {
                                return "<strong style='color: #1E0FBE's>" + value + "</strong>";
                            }
                            return ""
                        }
                    },
                    {
                        field: 'creditNumber',
                        title: '卡号',
                        align: 'center',
                    },
                    {
                        field: 'bankName',
                        align: 'center',
                        title: '所属银行',
                        formatter: function (value, row, index) {
                            if (value != null && value != "") {
                                return "<strong style='color: #1E0FBE's>" + value + "</strong>";
                            }
                            return ""
                        }
                    },
                    {
                        field: 'amountMoney',
                        align: 'center',
                        title: '交易金额',
                        formatter: function (value, row, index) {
                            return "<strong style='color: red's>" + value + "</strong>";
                        }
                    },
                    {
                        field: 'profitMoney',
                        title: '收益',
                        align: 'center',
                        formatter: function (value, row, index) {
                            return "<strong style='color: red's>" + value + "</strong>";
                        }
                    },
                    {
                        field: 'clearingStatus',
                        align: 'center',
                        title: '清分状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(orderClearing, value);
                        }
                    },
                    {
                        field: 'createTime',
                        title: '订单创建时间',
                        align: 'center',
                    },
                    {
                        field: 'completeTime',
                        title: '订单完成时间',
                        align: 'center',
                    },
                ]
            };
            $.table.init(options);
        }
    });

    function queryParams(params) {

        return {
            "params[completeTimeStartTime1]": $("#completeTimeStartTime1").val(),
            "params[completeTimeEndTime1]": $("#completeTimeEndTime1").val(),
            tradeType: $("#tradeType").val(),
            pageSize: params.limit,
            pageNum: params.offset / params.limit + 1,
            searchValue: params.search,
            orderByColumn: params.sort,
            isAsc: params.order
        };
    }

    //订单详情
    function detail(id) {
        var url = prefix + '/detail/' + id;
        createMenuItem(url, "查看详情");
    }

    //无卡出款
    function daiFuRepairOrderGGWK(id) {
        $.modal.confirm("确认要无卡出款吗？", function () {
            $.operate.post(prefix + "/daiFuRepairOrderGGWK/", {"id": id});
        })
    }

    //养卡消费退款
    function daiFuRepairOrderGG(id) {
        $.modal.confirm("确认要退款吗？", function () {
            $.operate.post(prefix + "/daiFuRepairOrderGG/", {"id": id});
        })
    }

    //查询订单
    function findOrderGG(id) {
        $.modal.confirm("确认要查询订单吗？", function () {
            $.operate.post(prefix + "/findOrderGG/", {"id": id});
        })
    }

    function parseFormatNum(number, n) {

        if (n != 0) {
            n = (n > 0 && n <= 20) ? n : 2;
        }
        number = parseFloat((number + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
        var sub_val = number.split(".")[0].split("").reverse();
        var sub_xs = number.split(".")[1];
        var show_html = "";
        for (i = 0; i < sub_val.length; i++) {
            show_html += sub_val[i] + ((i + 1) % 3 == 0 && (i + 1) != sub_val.length ? "," : "");
        }
        if (n == 0) {
            return show_html.split("").reverse().join("");
        } else {
            return show_html.split("").reverse().join("") + "." + sub_xs;
        }
    }
</script>
</body>
</html>